package com.ly.service.impl;

import com.ly.dao.AboutUsMapper;
import com.ly.pojo.domain.AboutUsDO;
import com.ly.pojo.dto.AboutUsDTO;
import com.ly.pojo.query.AboutUsQuery;
import com.ly.service.AboutUsService;
import java.lang.Boolean;
import java.lang.Override;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ly.exception.BusinessException;
import java.util.Map;
import com.ly.constant.ResultCodeConstant;
import java.util.Date;

/**
 * 关于我们管理的实现
 *
 * @author Administrator
 * @date 2025-03-07 10:51:13
 */
@Service
public class AboutUsServiceImpl implements AboutUsService {

    @Autowired
    private AboutUsMapper aboutUsMapper;

    @Override
    public Boolean editAboutUs(AboutUsDTO aboutUsDTO) {
        AboutUsDO aboutUsDO = aboutUsMapper.selectById(aboutUsDTO.getAboutUsId());
        if (aboutUsDO == null) {
            throw new BusinessException(ResultCodeConstant.CODE_000001, ResultCodeConstant.CODE_000001_MSG);
        }
        aboutUsDO.setContent(aboutUsDTO.getContent());
        aboutUsDO.setImageUrl(aboutUsDTO.getImageUrl());
        // 假设当前操作人是admin
        aboutUsDO.setUpdateBy("admin");
        aboutUsDO.setUpdateTime(new Date());
        int result = aboutUsMapper.updateById(aboutUsDO);
        return result > 0;
    }

    @Override
    public AboutUsDO aboutUsInfo(AboutUsQuery aboutUsQuery) {
        AboutUsDO aboutUsDO = aboutUsMapper.selectById(aboutUsQuery.getAboutUsId());
        if (aboutUsDO == null) {
            throw new BusinessException(ResultCodeConstant.CODE_000001, ResultCodeConstant.CODE_000001_MSG);
        }
        return aboutUsDO;
    }

    @Override
    public AboutUsDO latestAboutUsInfo() {
        AboutUsDO aboutUsDO = aboutUsMapper.selectLatest();
        return aboutUsDO;
    }

    @Override
    public Boolean deleteAboutUs(AboutUsQuery aboutUsQuery) {
        AboutUsDO aboutUsDO = aboutUsMapper.selectById(aboutUsQuery.getAboutUsId());
        if (aboutUsDO == null) {
            throw new BusinessException(ResultCodeConstant.CODE_000001, ResultCodeConstant.CODE_000001_MSG);
        }
        int result = aboutUsMapper.deleteById(aboutUsQuery.getAboutUsId());
        return result > 0;
    }
}
